package com.ztools.pc.controller.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.common.model.pc.sys.DictData;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.Result;
import com.ztools.common.util.pc.TokenAuthorization;
import com.ztools.pc.service.sys.DictDataService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: seeTools
 * @Date: 2023/5/22  19:30
 * @Version 1.0
 */
@RestController
@RequestMapping("/sys/dict/data")
public class DictDataController {

    @Resource
    private DictDataService dictDataService;

    @RequestMapping("/list")
    @TokenAuthorization("/sys/dict/search")
    public Result findList(@RequestBody PageUtil<DictData> pageUtil) {
        Page<DictData> list = dictDataService.findList(pageUtil);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestBody DictData dictData) {
        boolean b = dictDataService.delete(dictData);
        return b ? Result.success("删除成功") : Result.error();
    }

    @RequestMapping("/add")
    public Result add(@RequestBody DictData dictData) {
        boolean b = dictDataService.save(dictData);
        return b ? Result.success("添加成功") : Result.error();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody DictData dictData) {
        boolean b = dictDataService.update(dictData);
        return b ? Result.success("修改成功") : Result.error();
    }
}
